home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0051_Get SUB STRING at RIGHT.pas < prev    next >
Pascal/Delphi Source File  |  1993-09-26  |  2KB  |  79 lines

  1. {*****************************************************************************
  2.  * Function ...... RightAt()
  3.  * Purpose ....... Return the last position of a substring as viewed from
  4.  *                 the right side of the string
  5.  * Parameters .... sub       Substring to locate
  6.  *                 s         String to find <sub> in
  7.  * Returns ....... Numeric last position of <sub> in s, counting from
  8.  *                 right to left.
  9.  * Notes ......... None
  10.  * Author ........ Martin Richardson
  11.  * Date .......... October 2, 1992
  12. *****************************************************************************}
  13. FUNCTION RightAt( sub: STRING; s: STRING ): BYTE; ASSEMBLER;
  14. VAR
  15.    nResult: WORD;
  16. ASM
  17.       PUSH    DS
  18.       XOR     CX, CX
  19.  
  20.       LDS     SI, sub
  21.       XOR     AX, AX
  22.       LODSB
  23.       MOV     BX, AX
  24.       CMP     BX, 0
  25.       JBE     @@3
  26.  
  27.       LES     DI, s
  28.       XOR     DX, DX
  29.       MOV     DL, BYTE PTR ES:[DI]
  30.       INC     DI
  31.       CMP     DX, 0
  32.       JBE     @@3
  33.  
  34.       PUSH    DX
  35.  
  36.       CMP     BX, DX
  37.       JAE     @@3
  38.  
  39.       DEC     BX
  40.       CLD
  41. @@1:  MOV     SI, WORD PTR sub
  42.       INC     SI
  43.       LODSB
  44.  
  45.       MOV     CX, DX
  46.       REPNE   SCASB
  47.       JNZ     @@3
  48.  
  49.       MOV     DX, CX
  50.       MOV     CX, BX
  51.       REPE    CMPSB
  52.       JZ      @@4
  53.  
  54.       ADD     DI, CX
  55.       SUB     DI, BX
  56. @@2:  CMP     DX, BX
  57.       JA      @@1
  58. @@3:  XOR     AL, AL
  59.       JMP     @@5
  60. @@4:  SUB     DI, BX
  61.       DEC     DI
  62.       SUB     DI, WORD PTR s
  63.       MOV     nResult, DI
  64.       ADD     DI, WORD PTR s
  65.       ADD     DI,CX
  66.       INC     DI
  67.       JMP     @@2
  68. @@5:
  69.       POP     BX
  70.       MOV     AX, nResult
  71.       CMP     AX, 0
  72.       JE      @@6
  73.       XCHG    AX, BX
  74.       SUB     AX, BX
  75.       INC     AX
  76. @@6:  POP     DS
  77. END;
  78.  
  79.